package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@Slf4j
@RequestMapping("/admin/common")
@RestController
public class CommonController {

    @Autowired
    private AliOssUtil aliOssUtil;

    @RequestMapping("/upload")
    Result upload(MultipartFile file) throws Exception {
        log.info("file:{}",file.getOriginalFilename());
        String newFileName = aliOssUtil.upload(file.getBytes(), file.getOriginalFilename());
        log.info("文件上传后的URL:{}",newFileName);
        return Result.success(newFileName);

    }
}
